from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, DATETIME, MetaData, ForeignKey, Table
from sqlalchemy.dialects.mysql import (INTEGER, CHAR)

engine = create_engine("mysql+pymysql://root:wjl12345@localhost:3306/test?charset=utf8", echo=True, pool_size=5,
                       max_overflow=4, pool_recycle=7200, pool_timeout=30)
Base = declarative_base()


class mytable(Base):
    __tablename__ = 'mytable'
    id = Column(Integer, primary_key=True)
    Name = Column(String(50), unique=True)
    age = Column(Integer)
    birth = Column(DATETIME)
    class_name = Column(String(50))


Base.metadata.create_all(engine)
meta = MetaData()
myclass = Table('myclass', meta, Column('id', INTEGER, primary_key=True),
                Column('name', CHAR(50), ForeignKey(mytable.Name)),
                Column('class_name', CHAR(50)))
myclass.create(bind=engine)
myclass.drop(bind= engine)
Base.metadata.drop_all(engine)